import java.io.File;
import java.util.Scanner;



/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-24
 * Time: 13:33
 */
public class Demo1 {
    public static void main(String[] args) {
        System.out.println("请输入一个目录");
        Scanner scanner = new Scanner(System.in);
        String str=scanner.next();
        System.out.println("请输入一个关键词");
        String des = scanner.next();
        File f1 = new File(str);
        if(!f1.isDirectory()){
            System.out.println("路径错误");
            return;
        }
        search(f1,des);
    }
    public static  void search(File f,String des){
        File[] files = f.listFiles();
        if(files==null){
            return ;
        }
        for (File file:files ) {
            if(file.isFile()){
                String str = file.getName();
                if(str.contains(des)){
                    System.out.println(file.getAbsolutePath());
                    System.out.println("是否要删除该文件");
                    System.out.println("*******0:删除******");
                    System.out.println("*******1:保留******");
                    Scanner scanner =new Scanner(System.in);
                    int flg = scanner.nextInt();
                    if(flg==0){
                        file.delete();
                        System.out.println("删除成功!");
                    }


                }
            }else{
                search(file,des);
            }
        }
    }
}
